﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using LeHouse.Server.Dto;
using LeHouse.Server.Service;
namespace LeHouse.Server.WebApi.Controllers
{
    public class ZoneController : ApiController
    {
        Collateral_ZoneService bll = new Collateral_ZoneService();
        /// <summary>
        /// 抵押物区位状况的数据添加
        /// </summary>
        /// <param name="parms">ajax传过来的需要添加的数据</param>
        /// <returns></returns>       
        [HttpPost]
        [Route("api/Zone/PostInsert")]
        public bool Insert([FromBody] Collateral_Zone parms)
        {
            Collateral_PersonalService PerService = new Collateral_PersonalService();
            Collateral_Personal state = PerService.Select(p => p.T_ReportNumber == parms.T_ReportNumber).FirstOrDefault();
            if (state.T_State >= 2 && state.T_State != 4)
            {
                return false;
            }
            else
            {
                try
                {
                    if (bll.IsCount(parms.T_ReportNumber) > 0)
                    {
                        return bll.Update(parms, t => t.T_ReportNumber == parms.T_ReportNumber);
                    }
                    else
                    {
                        return bll.Insert(parms);
                    }
                }
                catch
                {
                    return false;
                }
            }

        }

        //  <summary>
        // 查看抵押物区位状况表的所有数据by  id
        //  </summary>
        //   <returns></returns>
        //[HttpGet]
        //[Route("api/Zone/selectbyid")]
        //public Collateral_Zone selectbyid([FromUri] string P_ReportNumber)
        //{
        //    //var v = Request.Content;
        //    if (bll.IsCount(P_ReportNumber) > 0)
        //    {
        //        Collateral_ZoneService select = new Collateral_ZoneService();
        //        return select.Community(P_ReportNumber);
        //    }
        //    else
        //    {
        //        return null;
        //    }

        //}
    }
}
